<?php
//
//	file: includes/calendar/class_calendar_init.php
//	author: ptirhiik
//	begin: 01/02/2006
//	version: 1.6.0 - 29/06/2008
//	license: http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
//

if ( !defined('IN_PHPBB') )
{
	die('Hacking attempt');
}

// define if we need the lang
if ( !defined('IN_CALENDAR') && !$gen_simple_header )
{
	$user->use_lang(array('class_forums', 'class_topics', 'class_posts', 'viewprofile'));
}

// our date/time manager
include($config->url('includes/calendar/class_calendar_api'));

// define the external version file
class calendar_version
{
	function read(&$data)
	{
		$data[] = array('app_name' => 'Topic calendar CH edition', 'app_desc' => '', 'app_marker' => 'mod_topic_calendar_CH', 'app_author' => 'Ptirhiik', 'app_author_url' => 'http://ptifo.clanmckeen.com', 'app_server' => 'ptifo.clanmckeen.com', 'app_file' => '/download/versions.dta', 'app_protocol' => 'native', 'app_page' => 'http://ptifo.clanmckeen.com/download.php');
	}
}

class calendar_config
{
	var $api;
	var $event_categories;
	var $event_types;
	var $modules;

	function calendar_config()
	{
		$this->api = false;
		$this->event_categories = array();
		$this->modules = array();
		$this->even_types = false;
	}

	function set($event_desc)
	{
		global $config;
		$this->api = new calendar_api();
		$this->even_types = array();

		$plugs = array();
		foreach ( $event_desc as $type => $desc )
		{
			if ( isset($desc['layer']) )
			{
				$this->event_types[$type] = $desc['layer'];
			}
			if ( isset($desc['plugs']) && $desc['plugs'] )
			{
				foreach ( $desc['plugs'] as $api_id => $api_desc )
				{
					if ( !isset($plugs[$api_id]) )
					{
						$plugs[$api_id] = array('layer' => array(), 'object' => array());
					}
					if ( isset($api_desc['layer']) )
					{
						$plugs[$api_id]['layer'] = array_merge($plugs[$api_id]['layer'], is_array($api_desc['layer']) ? $api_desc['layer'] : array($api_desc['layer']));
					}
					if ( isset($api_desc['object']) )
					{
						$plugs[$api_id]['object'] = array_merge($plugs[$api_id]['object'], is_array($api_desc['object']) ? $api_desc['object'] : array($api_desc['object']));
					}
				}
			}
		}
		if ( $plugs )
		{
			$config->set_plug_ins('mod_topic_calendar_CH', $plugs);
		}
	}

	function get_modules()
	{
		global $config;

		$res = array();
		foreach ( $this->event_types as $class => $filenames )
		{
			$res[$class] = false;
			if ( $filenames )
			{
				if ( !is_array($filenames) )
				{
					$filenames = array($filenames);
				}
				$res[$class] = array();
				$count_filenames = count($filenames);
				for ( $i = 0; $i < $count_filenames; $i++ )
				{
					if ( $filenames[$i] && ($filename = $config->url($filenames[$i])) && @file_exists(phpbb_realpath($filename)) )
					{
						$res[$class][] = $filename;
					}
				}
			}
			if ( empty($res[$class]) )
			{
				$res[$class] = false;
			}
		}
		return empty($res) ? false : $res;
	}

	function add_module($module)
	{
		if ( class_exists($module) )
		{
			$this->modules[] = $module;
		}
	}

	function add_event_categories($cats)
	{
		$this->event_categories += $cats;
		ksort($this->event_categories);
	}
}
$config->globals['mod_topic_calendar_CH'] = new calendar_config();

//-------------------------------
// registration of event type :
// class => [layer => file, plugs => [layer => plug_file(s), object => plug_object(s)] ]
//-------------------------------
$config->globals['mod_topic_calendar_CH']->set(array(
	// all event types
	'*all' => array(
		'plugs' => array(
			'page_header' => array(
				'layer' => 'includes/calendar/class_calendar_page_header',
				'object' => 'calendar_page_header',
			),
			'class_versions' => array(
				'object' => 'calendar_version',
			),
		),
	),
	// topics
	'calendar_event_topics' => array(
		'layer' => 'includes/calendar/topics/class_calendar_topics',
		'plugs' => array(
			'posting' => array(
				'layer' => 'includes/calendar/topics/class_calendar_topics_posting',
				'object' => 'calendar_topics_posting',
			),
			'admin/admin_icons' => array(
				'layer' => 'includes/calendar/topics/class_calendar_topics_plugs',
				'object' => 'calendar_admin_icons',
			),
			'class_forums' => array(
				'layer' => 'includes/calendar/topics/class_calendar_topics_plugs',
				'object' => 'calendar_forums',
			),
			'class_posts' => array(
				'layer' => 'includes/calendar/topics/class_calendar_topics_plugs',
				'object' => 'calendar_posts',
			),
			'front_title' => array(
				'layer' => 'includes/calendar/topics/class_calendar_topics_plugs',
				'object' => 'calendar_front_title',
			),
		),
	),
	//
	// birthdays
	// ---------
	// uncomment the appropriate line if you have a birthday mod installed
	// using phpbb_users.user_birthday field with one of the following format:
	//
	'calendar_event_birthday' => array(
// mmddyyyy, integer
//		'layer' => array('includes/calendar/birthday/class_calendar_birthday_drv_mdy', 'includes/calendar/birthday/class_calendar_birthday'),
// yyyymmdd char(8), with leading 0
//		'layer' => array('includes/calendar/birthday/class_calendar_birthday_drv_ymd', 'includes/calendar/birthday/class_calendar_birthday'),
// dd-mm-yyyy varchar(10), without leading 0 for the date components
//		'layer' => array('includes/calendar/birthday/class_calendar_birthday_drv_dmy_sep', 'includes/calendar/birthday/class_calendar_birthday'),
	),
));

?>